
% Matlab/Octave script
% Plotting of surface nearfield enhancement - mostly for show
% SWH Feb 2012

close all
clear all

% read of rick results of Poynting for 50 nm gold particles in water exposed to 780nm light
Er=load('..//inputs//poynting_50_780_block.txt');
[yy,xx]=size(Er);
%xx %181
%yy %361
y2=(yy-1)/2;
x2=(xx-1)/2;
Er_s=Er(y2:yy-1,x2:xx-1);
xphi=(0:1:x2);
ytheta=(0:1:y2);

% plotting surface
figure(1);
surf(xphi,ytheta,Er_s,'FaceColor','interp','EdgeColor','none');%,'Facelighting','phong');
axis tight
axis square
xlabel('\phi','fontsize',15);
ylabel('\theta','fontsize',15);
zlabel('Poynting |S|');
colorbar%('location','southoutside');
%camlight left

% this block if Er is not a full sphere i.e., pi x 2pi
%Er_q = Er(1:91,1:91);
%[sy,sx]=size(Er_q);
%Eflip1=zeros(sy,sx);
%for ii=1:sx
%   Eflip1(:,sx-ii+1)=Er_q(:,ii);
%end
%Eflip2=zeros(sy,sx);
%for ii=1:sy
%   Eflip2(sy-ii+1,:)=Er_q(ii,:);
%end
%Eflip3=zeros(sy,sx);
%for jj=1:sx
%   for ii=1:sy
%      Eflip3(sy-ii+1,sx-jj+1)=Er_q(ii,jj);
%   end
%end

%Er_tot1=zeros(sy*4-3,sx*2-1);
%Er_tot1(1:sx,1:sy)=Eflip1;
%Er_tot1(sx:2*sx-1,1:sy)=Eflip3;
%Er_tot1(2*sx-1:3*sx-2,1:sy)=Eflip1;
%Er_tot1(3*sx-2:4*sx-3,1:sy)=Eflip3;
%Er_tot1(1:sx,sy:sy*2-1)=Er_q;
%Er_tot1(sx:2*sx-1,sy:sy*2-1)=Eflip2;
%Er_tot1(2*sx-1:3*sx-2,sy:sy*2-1)=Er_q;
%Er_tot1(3*sx-2:4*sx-3,sy:sy*2-1)=Eflip2;
%Er_tot=Er_tot1';

% plotting surface contour
figure(3)
%contour(Er_tot);
contour(Er);

n=360;
[sy,sx]=size(Er);
[sya,sxa]=meshgrid(1:sy*4-3,1:sx*2-1);
[my,mx]=meshgrid(1:(sy*4-3)/n:sy*4-2,1:(sx*2-1)/n:sx*2);
Er_small=interp2(sya,sxa,Er',my,mx,'cubic');

% plotting sphere
[qq,ww,ee]=sphere(n);
figure(2);
surface(qq,ww,ee,Er_small,'EdgeColor','none');
%axis("square");
axis("off");
colorbar
caxis([0 4])
view(-37.5,30);
